<template>
  <view class="container">
    <view class="example">
      <uni-forms ref="form" :model="storeAddForm" :rules="rules" labelWidth="80px">
        <uni-forms-item label="饲料类型" name="materiaFeedType" required>
          <uni-data-select v-model="storeAddForm.materiaFeedType" placeholder="请选择饲料类型"
          	:localdata="material_type"
            ></uni-data-select>
        </uni-forms-item>
		<uni-forms-item label="存储地点" name="materiaFeedStorePosition" required>
		  <uni-data-select v-model="storeAddForm.materiaFeedStorePosition" placeholder="请选择存储地点"
		  	:localdata="store_position"
		    ></uni-data-select>
		</uni-forms-item>
		<uni-forms-item label="数量" name="materiaFeedStoreNum" required>
		  <uni-easyinput type="number" v-model="storeAddForm.materiaFeedStoreNum" placeholder="请输入数量(KG)" />
		</uni-forms-item>
		<uni-forms-item label="进仓时间" name="materiaFeedStoreTime" required>
		  <uni-datetime-picker type="datetime" v-model="storeAddForm.materiaFeedStoreTime"/>
		</uni-forms-item>
		<uni-forms-item label="备注">
			<uni-easyinput type="textarea" v-model="storeAddForm.remark" placeholder="请输入备注" />
		</uni-forms-item>
      </uni-forms>
      <button class="buttonAdd" type="primary" plain="true" @click="submit('form')">提交</button>
    </view>
  </view>
</template>

<script>
import {
		addStore, getTypes
	} from "@/api/hmy/material";

export default {
  name: "StoreAdd",
  data() {
    return {
		//饲料类型
		 material_type:[],
		typesList:[],
		typesList:[],
		store_position:[
			{ text: '一号仓库', value: 1},
			{ text: '二号仓库', value: 2},
			{ text: '三号仓库', value: 3}
		],
		storeAddForm: {},
		rules: {
			materiaFeedType: {
				rules: [{required: true, errorMessage: '饲料种类不能为空'}]
			},
			materiaFeedStoreNum: {
				rules: [{required: true, errorMessage: '数量不能为空'}]
			},
			materiaFeedStorePosition: {
				rules: [{required: true, errorMessage: '存储地点不能为空'}]
			},
			materiaFeedStoreTime: {
				rules: [{required: true, errorMessage: '进仓时间不能为空'}]
			}
	    },
	}
  },
  created(){
  	  this.getTypesList();
  },
  methods: {
	  //动态获取饲料数据
	  getTypesList(){
	    getTypes().then(res => {
	  	this.typesList = res.data;
	  	this.typesList.forEach((item,index) => {
	  		this.material_type.push({
	  			'text': item.materiaFeedType,
	  			'value': item.materiaFeedTypeId
	  		})
	  	})
	    })
	  },
    submit(form) {
      this.$refs[form].validate().then(res => {
        addStore(this.storeAddForm).then(response => {
          this.$modal.msgSuccess("新增成功")
		  setTimeout(()=>{
		  	this.$tab.navigateTo('/pages/hmy/material/store');
		  },1000)
		  
        })
      })
    },
  }
}
</script>

<style lang="scss">
	
  /* #ifndef APP-NVUE */
  page {
	  background-color: #fff;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100%;
    height: auto;
  }

  view {
    font-size: 16px;
    line-height: inherit;
  }
  /* #endif */



  
  .example {
    padding: 15px;
    background-color: #fff;
  }
  
  .buttonAdd{
	  width:90%;
	  position:fixed;
	  bottom:10px;
  }
</style>

